import {
  GetEventDetail,
  UpAssess
} from '../../../../config/api'
import util from '../../../../utils/util'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    member:'',
    id:'',
    RecordDetail: {}, //记录详情
    items: [{
      value: 3,
      name: '非常满意',
      checked: 'true'
    },
    {
      value: 2,
      name: '满意'
    },
    {
      value: 1,
      name: '不满意'
    }
    ],
    level: 3, // 默认非常满意
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    let member = wx.getStorageSync("member");

    this.setData({
      member,
      id: options.id
    })

    this.getDetail()
  },

  getDetail(){
    let that =this;
    util.apiRequest(GetEventDetail, {
      id: that.data.id,
    }, null).then(r => {
      console.log('事件记录详情：', r)
      that.setData({
        RecordDetail: r.data.data
      })
    });
  },

  // 预览事件内容图片
  previewAttach: function (e) {
    let that = this;
    var index = e.currentTarget.dataset.index;
    console.log('预览index', index);
    let imgs = that.data.RecordDetail.attach;
    // console.log('imgs', that.data.Imgs);
    wx.previewImage({
      //当前显示图片
      current: imgs[index],
      //所有图片
      urls: imgs
    })
  },

  // 预览事件处理图片
  previewReplyImg: function (e) {
    console.log('预览处理图片e:', e)
    let that = this;
    var index = e.currentTarget.dataset.index;
    var pindex = e.currentTarget.dataset.pindex;

    console.log('aa预览index', index);

    let imgs = this.data.RecordDetail.handle_log[pindex].attach

    wx.previewImage({
      //当前显示图片
      current: imgs[index],
      //所有图片
      urls: imgs
    })
  },

  radioChange(e) { // 选择评价
    console.log('radio携带value值为：', e.detail.value)

    const items = this.data.items
    for (let i = 0, len = items.length; i < len; ++i) {
      console.log('每一个item', items[i].value)
      items[i].checked = items[i].value == e.detail.value
    }

    console.log('复制后', items)

    this.setData({
      level: e.detail.value,
      items
    })
  },

  submitPj(e) { // 提交评价
    let that = this;
    let params = {
      type: 1,
      level: that.data.level,
      eid: that.data.id,
      uid: this.data.member.id,
      u_name: this.data.member.name,
      vollege_id: this.data.member.vollege_id,
      town_id: this.data.member.town_id,
    }
    util.apiRequest(UpAssess, params).then(r => {
      console.log('评价后', r)
      if (r.data.code == 1) {
        this.getDetail(); // 重新渲染列表数据
        wx.showToast({
          icon: 'none',
          title: '评价成功',
        })
      }
    })
  },


  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})